% -- A Ramsey Theory of Financial Distortions --
% Parameterization
% Written by Wei Cui, w.cui@ucl.ac.uk
% Last update: Feb, 2023

clc; clear;  close all; format short


%% Initialization
%%%% Exogenous parameters
par.A           = 1;               % productivity
par.BETA        = 0.97;            % discount factor
par.ALPHA       = 0.33;            % capital share
par.SIGMA       = 1;               % consumption function curvature
par.NU          = 1/1.5;           % inverse labor supply elasticity
par.CHI         = 0.16;            % population of entrepreneurs
par.eta_0       = 0.45;            % intermediation cost parameter 1 (does not matter here)
par.eta_1       = 2;               % intermediation cost parameter 2 (does not matter here)

%%%% Targets. Note: G, DELTA, and MU will be calibrated
par.G_Y         = 0.20;             % government spending / output ratio
par.I_Y         = 0.2502;
par.L_target    = 1/3;

%% Compute steady state and calibrate parameters

%%%% Pass structure 'par' to AMPL data file
cd steady_state_transition_AMPL
data_file = 'consumption_saving.dat'; % to be used in writing_data_to_AMPL.m
data_     = par; % to be used in writing_data_to_AMPL.m

writing_data_to_AMPL % writing data to what can be inputed to AMPL


%%%% Run unconstrained solution (not the top of the Laffer curve)
%%%% Note: we did try constrained model; with sigma = 1, it has no solution
system('ampl ss_unconstrained_cali.run');

%par         = rmfield(par, {'G_Y', 'I_Y', 'L_target'}); % remove par.G_Y etc as we have now par.G

%%%% Pass AMPL output to structure 'par' (not strictly necessary)
output_file = 'eqm_result.csv';

writing_data_from_AMPL % the output is the set of parameters
for i = 1:length(parameters)
   par.(parameters{i,1}) = parameters{i,2};
end
cd ..

par_calibrated = par;
save param par_calibrated % Save the calibrated values for later use